package zozopo.oa;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.operations.oa.AddressbookOS;
import zozopo.operations.oa.AddressbookTB;
import zozopo.user.operations.UserTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class AddAddressbookAction extends ActionSupport implements Action,SessionAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String limitedCode ="OA.ADDRESSBOOK.ADD";
	
	private Map<Object, Object> session;
	
	//List<AddressbookTB> addressbookList;
	
	private String name;
	private String mobile;
	private String phone;
	private String qq;
	private String company;
	private String address;
	private String departments;
	private String jobs;
	private String duties;
	private String status;
	private String des;
	private String kind;
	private String lable;
	
	private String operationResult;
	
	public String execute(){
		AddressbookOS addressbookOS = new AddressbookOS();
		AddressbookTB addressbook = new AddressbookTB();
		
		addressbook.setCompany_addressbook(company);
		addressbook.setDepartments_addressbook(departments);
		addressbook.setDes_addressbook(des);
		addressbook.setDuties_addressbook(duties);
		addressbook.setJobs_addressbook(jobs);
		addressbook.setKind_addressbook(kind);
		addressbook.setLable_addressbook("");
		addressbook.setMobile_addressbook(mobile);
		addressbook.setName_addressbook(name);
		addressbook.setPhone_addressbook(phone);
		addressbook.setQq_addressbook(qq);
		addressbook.setAddress_addressbook(address);
		
		if(addressbookOS.addAddressbook(addressbook)){
			operationResult = addressbook.getName_addressbook() + " 添加成功!";
			addressbookOS.releaseConnection();
			return SUCCESS;
		}else{
			operationResult = addressbook.getName_addressbook() + "未能正常添加 ,系统出错!";
			addressbookOS.releaseConnection();
			return ERROR;
		}
		
		
		
	}
	
	public void validate() {
		//权限处理
		UserTB user = (UserTB) session.get("userInfo");
		
		if(user == null){
			addFieldError("errormessage",getText("user.timeoutornotlogin"));
			return ;
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> userlimitedMap = (Map<String,OperatorlimitedTB>)session.get("userlimitedMap");
		
		if(userlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户添加通讯录权限.");
			return;
		}
		
		
	}

	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getDepartments() {
		return departments;
	}

	public void setDepartments(String departments) {
		this.departments = departments;
	}

	public String getJobs() {
		return jobs;
	}

	public void setJobs(String jobs) {
		this.jobs = jobs;
	}

	public String getDuties() {
		return duties;
	}

	public void setDuties(String duties) {
		this.duties = duties;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getDes() {
		return des;
	}

	public void setDes(String des) {
		this.des = des;
	}

	public String getKind() {
		return kind;
	}

	public void setKind(String kind) {
		this.kind = kind;
	}

	public String getLable() {
		return lable;
	}

	public void setLable(String lable) {
		this.lable = lable;
	}

	public String getOperationResult() {
		return operationResult;
	}

	public void setOperationResult(String operationResult) {
		this.operationResult = operationResult;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
}
